//
// Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
//
// GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
//  Author: Shawn.Tan
//  Date : 2025.10.28
//
//  History : Initial Version 2025.10.28
//
//
#ifndef Green_PyThreadDispatcher_H
#define Green_PyThreadDispatcher_H

#include "pybind11/pybind11.h"

#include "Scheduler.h"
#include "ThreadDispatcher.h"

namespace py = pybind11;

namespace Green {

  PYBIND11_MODULE(ThreadDispatcher, mod) {
    py::class_<ThreadDispatcher>(mod, "ThreadDispatcher")
      .def_static("getCurrentDispatcher", &ThreadDispatcher::GetCurrentDispatcher, py::return_value_policy::reference /* No call guard because never blocks */)
      .def_static("setCurrentDispatcher", &ThreadDispatcher::SetCurrentDispatcher /* No call guard because only intended for specific use cases of thread executor */)
      ;

    py::class_<MultiThreadDispatcher, ThreadDispatcher>(mod, "MultiThreadDispatcher")
      .def(py::init([]() {
          return new MultiThreadDispatcher(Scheduler::Instance());
        }) /* No call guard because never blocks */)
      .def("start", &MultiThreadDispatcher::Start, py::call_guard<py::gil_scoped_release>())
      .def("stop", &MultiThreadDispatcher::Stop, py::call_guard<py::gil_scoped_release>())
      .def("request", &MultiThreadDispatcher::Request, py::call_guard<py::gil_scoped_release>())
      .def("finish", &MultiThreadDispatcher::Finish /* No call guard because never blocks */)
      .def("addThreadId", &MultiThreadDispatcher::AddThreadId, py::call_guard<py::gil_scoped_release>())
      .def("registerExecutionThread", &MultiThreadDispatcher::RegisterExecutionThread, py::call_guard<py::gil_scoped_release>())
      .def("reportThreadDone", &MultiThreadDispatcher::ReportThreadDone, py::call_guard<py::gil_scoped_release>())
      ;

    py::class_<SingleThreadDispatcher, ThreadDispatcher>(mod, "SingleThreadDispatcher")
      .def(py::init() /* No call guard because never blocks */)
      .def("start", &SingleThreadDispatcher::Start /* No call guard because never blocks */)
      .def("stop", &SingleThreadDispatcher::Stop /* No call guard because never blocks */)
      .def("request", &SingleThreadDispatcher::Request /* No call guard because never blocks */)
      .def("finish", &SingleThreadDispatcher::Finish /* No call guard because never blocks */)
      .def("addThreadId", &SingleThreadDispatcher::AddThreadId /* No call guard because never blocks */)
      ;
  }

}

#endif  // Green_PyThreadDispatcher_H
